package com.whz.work.ex02.servlet;

import com.whz.work.ex02.Constants;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName PrimitiveServlet
 * @Description TODO
 * @Author hong-zhi
 * @Date 2021/5/28 20:29
 * @Version 1.0
 */
@Slf4j
public class PrimitiveServlet implements Servlet {
    static {
        System.out.printf("类PrimitiveServlet完成了初始化\n");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        log.info("我刚刚完成了初始化");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest request, ServletResponse response)
            throws ServletException, IOException {
        log.info("开始服务调用");
        PrintWriter out = response.getWriter();


        out.print("HToP/1.1 200 OK");
        out.print(Constants.CRLF);
        out.print("<html><body><span>红玫瑰</span></body></html>");
        out.print("白玫瑰");
        out.flush();
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        log.info("我被销毁了");

    }
}
